<{capture name="header"}>
<{css app='omeauto' src="style.css"}>
<{/capture}>
<h5 class="head-title">自动确认订单规则添加/编辑</h5>
<form action="index.php?app=omeauto&ctl=autoconfirm&act=do_add" method="post">
<input type="hidden" name="oid" value="<{$autoconfirm.oid}>" />
<div class="tableform">
  <div class="division">
    <table width="100%" cellspacing="0" cellpadding="0">
      <tbody>
        <tr>
          <th width="10%"><label for="dom_el_bc">规则名称：</label></th>
          <td colspan="3"><{input type="text&&required" name="name" value=$autoconfirm.name}> <{help}><{t}>这里填写你需要添加的规则名称<{/t}><{/help}></td>
        </tr>
        <tr>
          <th><label for="dom_el">规则描述：</label></th>
          <td colspan="3"><textarea name="memo" cols="60" rows="4" class="x-input"><{$autoconfirm.memo|escape}></textarea> <{help}><{t}>这里填写你需要添加的规则描述<{/t}><{/help}></td>
        </tr>
        <tr>
          <th><label for="dom_el_bc79182">规则设置：</label></th>
          <td colspan="3">
              <p id="btn_add_condition">
              <{if $conditions}>
                <{foreach from=$conditions item=item}>
                <{if $item.disabled}>
                    <{button label=$item.name iname=$item.name id=$item.condition disabled='true'}>
                <{else}>
                    <{button label=$item.name iname=$item.name id=$item.condition}>
                <{/if}>
                <{/foreach}>
              <{/if}>
              </p>
              
              <h5>已设置的订单确认规则</h5>
              <div id="dataNode">
                <{foreach from=$condition_detail item=item}>
                <div class="added_item" key="<{$item.condition}>">
                <div class="th"><{$item.title}>：</div>
                <div class="td"><{$item.content}></div>
                <div class="del"><a href="javascript:void(0)">删除</a></div>
                </div>
                <{/foreach}>
              </div>
          </td>
        </tr>
        <tr>
          <th><label for="dom_el_bc79182">发货仓库设置：</label></th>
          <td colspan="3">
              <div>订单中所有商品都可以从一个仓库发货：<{help}>请注意：如果有多个仓库符合条件，则设置失效。<{/help}></div>
              <{input name="branch" type="radio" separator="<br>" value=$branch_condition options=$branch_condition_list }>
          </td>
        </tr>
        <tr>
          <th><label for="dom_el_bc79182">发货物流设置：</label></th>
          <td colspan="3">
              <{input name="dlycorp" type="radio" separator="<br>" value=$dlycorp_condition options=$dlycorp_condition_list }>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</div>
<div class="table-action">
  <{button class="btn-primary" label="保存" type="submit" id="saveCurrent"}>
</div>
</form>
<script type="text/javascript">
(function(){

    $('dataNode').getElements('.del').addEvent("click",function(){
        if(confirm('确认删除此条件?')){
            $(this.getParent().get('key')).disabled=false;
            this.getParent().destroy();
        }
    });
    $ES('#btn_add_condition button').each(function(item,i){
        item.addEvent('click',function(e){
            var id = item.get('id');
            var name = item.getProperty('iname');

            item.disabled=true;
            var added_item=new Element('.added_item',{html:'<div class="th"></div><div class="td"></div><div class="del"><a href="javascript:void(0)">删除</a></div>'}).inject('dataNode');
            new Request.HTML({
                url : 'index.php?app=omeauto&ctl=autoconfirm&act=show_condition_detail&p[0]='+id,
                method : 'post',
                evalScripts : true,
                update : added_item.getElement('.td'),
                onSuccess: function(){
                    added_item.getElement('.th').setHTML(name+'：');
                }
            }).send();
            added_item.getElement('.del').addEvent("click",function(){
                if(confirm('确认删除此条件?')){
                    item.disabled=false;
                    this.getParent().destroy();
                }
            });

        });
    });

    

    var form = $('saveCurrent').getParents('form');
    
    form.store('target',{
        onRequest:function(e){
            //提交按钮:disabled
            $('saveCurrent').set('disabled', 'true');
            $('saveCurrent').getElements('span')[1].set('text','正在保存');
        },
        onComplete:function(jsontext){
            //jsontext = jsontext.replace(/[\r\n]+/img, ' ');
            var json = Json.evaluate(jsontext);
            if (typeof(json.error) != 'undefined'){
                //提交按钮:enabled
                $('saveCurrent').set('disabled', '');
                $('saveCurrent').getElements('span')[1].set('text','保存');
            }else{
                //提交按钮:disabled
                opener.finderGroup["<{$env.get.finder_id}>"].refresh.delay(400,opener.finderGroup["<{$env.get.finder_id}>"]);
                setTimeout("window.close()",500);
            }
        }
    }); 
    
})();
</script>
